import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";
import store from '@/store'
Vue.use(VueRouter);

const routes = [
  {
    path: '/404',
    Comment: () => import('../views/w404.vue')
  },
  {
    path: '/',
    redirect: '/home/index'
  },
  {
    path: '/home/wash',
    redirect: '/home/wash/washappoint'
  },
  {
    path: "/home",
    name: "home",
    component: HomeView,
    children: [
      // {
      //   path: "index",
      //   name: "index",
      //   component: ()=>import("../views/Index.vue"),
      //   meta: {
      //     crumb: ['首页']
      //   }
      // },
      // {
      //   path: 'commondity',
      //   name: 'commondity',
      //   component: () => import('../views/petshop/Commondity.vue'),
      //   meta: {
      //     crumb: ['宠物店管理','商品管理']
      //   }
      // },
      // {
      //   path: 'commondity-add',
      //   name: 'commondity-add',
      //   component: () => import('../views/petshop/CommondityAdd.vue'),
      //   meta: {
      //     crumb: ['宠物店管理','添加商品']
      //   }
      // },
      // {
      //   path: 'commondity-audit',
      //   name: 'commondity-audit',
      //   component: () => import('../views/petshop/CommondityAudit.vue'),
      //   meta: {
      //     crumb: ['宠物店管理','商品审核']
      //   }
      // },
      // {
      //   path: 'commondity-list',
      //   name: 'commondity-list',
      //   component: () => import('../views/petshop/CommondityList.vue'),
      //   meta: {
      //     crumb: ['宠物店管理','商品列表']
      //   }
      // },
      // {
      //   path: 'commondity-update/:id',
      //   name: 'commondity-update',
      //   component: () => import('@/views/petshop/CommondityUpdate.vue'),
      //   meta:{
      //     crumb: ['宠物店管理','商品修改']
      //   }
      //   },
      // {
      //   path: 'wash',
      //   name: 'wash',
      //   component: () => import('../views/petshop/Wash.vue'),
      //   meta: {
      //     crumb: ['宠物店管理','预约']
      //   },
      //   children:[
      //     {
      //       path: 'washappoint',
      //       name: 'washappoint',
      //       component: () => import('../views/petshop/WashAppoint.vue'),
      //       meta:{
      //         keepAlive:true,
      //         crumb: ['宠物店管理','预约','洗护预约']
      //       },
      //     },
      //     {
      //       path: 'takepic',
      //       name: 'takepic',
      //       component: () => import('../views/petshop/TakePic.vue'),
      //       meta:{
      //         keepAlive:true,
      //         crumb: ['宠物店管理','预约','拍照预约']
      //       },
      //     },
      //     {
      //       path: 'fosterage',
      //       name: 'fosterage',
      //       component: () => import('../views/petshop/Fosterage.vue'),
      //       meta:{
      //         keepAlive:true,
      //         crumb: ['宠物店管理','预约','宠物寄养信息']
      //       },
      //     },
      //   ]
      // },
      // {
      //   path: 'message-audit',
      //   name: 'message-audit',
      //   component: () => import('../views/invitation/MessageAudit.vue'),
      //   meta: {
      //     crumb: ['社区管理','信息审核']
      //   }
      // },
      // {
      //   path: 'message-manage',
      //   name: 'message-manage',
      //   component: () => import('../views/invitation/MessageManage.vue'),
      //   meta: {
      //     crumb: ['社区管理','信息管理']
      //   }
      // },
      // {
      //   path: 'science-add',
      //   name: 'science-add',
      //   component: () => import('../views/science/ScienceAdd.vue'),
      //   meta: {
      //     crumb: ['科普管理','科普新增']
      //   }
      // },
      // {
      //   path: 'science-list',
      //   name: 'science-list',
      //   component: () => import('../views/science/ScienceList.vue'),
      //   meta: {
      //     crumb: ['科普管理','科普列表']
      //   }
      // },
      // {
      //   path: 'science-update/:science_id',
      //   name: 'science-update',
      //   component: () => import('../views/science/ScienceUpdate.vue'),
      //   meta: {
      //     crumb: ['科普管理','修改科普']
      //   }
      // },
      // {
      //   path: 'news-list',
      //   name: 'news-list',
      //   component: () => import('../views/news/NewsList.vue'),
      //   meta: {
      //     crumb: ['新闻管理','新闻列表']
      //   }
      // },
      // {
      //   path: 'news-add',
      //   name: 'news-add',
      //   component: () => import('../views/news/NewsAdd.vue'),
      //   meta: {
      //     crumb: ['新闻管理','新闻新增']
      //   }
      // },
      // {
      //   path: 'news-update/:news_id',
      //   name: 'news-update',
      //   component: () => import('../views/news/NewsUpdate.vue'),
      //   meta: {
      //     crumb: ['新闻管理','修改新闻']
      //   }
      // },
    ],
  },
  {
    path: "/about",
    name: "about",
    component: () =>
      import("../views/AboutView.vue"),
  },
  {
    path: "/login",
    name: "login",
    component: () =>
      import("../views/Login/Login.vue"),
  },  

];
const level1 = [
  {
    path: "index",
    name: "index",
    component: () => import("../views/Index.vue"),
    meta: {
      crumb: ['首页']
    }
  },
  {
    path: 'message-audit',
    name: 'message-audit',
    component: () => import('../views/invitation/MessageAudit.vue'),
    meta: {
      crumb: ['社区管理', '信息审核']
    }
  },
  {
    path: 'message-manage',
    name: 'message-manage',
    component: () => import('../views/invitation/MessageManage.vue'),
    meta: {
      crumb: ['社区管理', '信息管理']
    }
  },
  {
    path: 'science-add',
    name: 'science-add',
    component: () => import('../views/science/ScienceAdd.vue'),
    meta: {
      crumb: ['科普管理', '科普新增']
    }
  },
  {
    path: 'science-list',
    name: 'science-list',
    component: () => import('../views/science/ScienceList.vue'),
    meta: {
      crumb: ['科普管理', '科普列表']
    }
  },
  {
    path: 'science-update/:science_id',
    name: 'science-update',
    component: () => import('../views/science/ScienceUpdate.vue'),
    meta: {
      crumb: ['科普管理', '修改科普']
    }
  },
  {
    path: 'news-list',
    name: 'news-list',
    component: () => import('../views/news/NewsList.vue'),
    meta: {
      crumb: ['新闻管理', '新闻列表']
    }
  },
  {
    path: 'news-add',
    name: 'news-add',
    component: () => import('../views/news/NewsAdd.vue'),
    meta: {
      crumb: ['新闻管理', '新闻新增']
    }
  },
  {
    path: 'news-update/:news_id',
    name: 'news-update',
    component: () => import('../views/news/NewsUpdate.vue'),
    meta: {
      crumb: ['新闻管理', '修改新闻']
    }
  },
  {
    path: 'commondity-audit',
    name: 'commondity-audit',
    component: () => import('../views/petshop/CommondityAudit.vue'),
    meta: {
      crumb: ['宠物店管理', '商品审核']
    }
  }
]
const level2 = [
  {
    path: "index",
    name: "index",
    component: () => import("../views/Index.vue"),
    meta: {
      crumb: ['首页']
    }
  },
  {
    path: 'commondity',
    name: 'commondity',
    component: () => import('../views/petshop/Commondity.vue'),
    meta: {
      crumb: ['宠物店管理', '商品管理']
    }
  },
  {
    path: 'commondity-add',
    name: 'commondity-add',
    component: () => import('../views/petshop/CommondityAdd.vue'),
    meta: {
      crumb: ['宠物店管理', '添加商品']
    }
  },
  {
    path: 'commondity-list',
    name: 'commondity-list',
    component: () => import('../views/petshop/CommondityList.vue'),
    meta: {
      crumb: ['宠物店管理', '商品列表']
    }
  },
  {
    path: 'commondity-update/:id',
    name: 'commondity-update',
    component: () => import('@/views/petshop/CommondityUpdate.vue'),
    meta: {
      crumb: ['宠物店管理', '商品修改']
    }
  },
  {
    path: 'wash',
    name: 'wash',
    component: () => import('../views/petshop/Wash.vue'),
    meta: {
      crumb: ['宠物店管理', '预约']
    },
    children: [
      {
        path: 'washappoint',
        name: 'washappoint',
        component: () => import('../views/petshop/WashAppoint.vue'),
        meta: {
          keepAlive: true,
          crumb: ['宠物店管理', '预约', '洗护预约']
        },
      },
      {
        path: 'takepic',
        name: 'takepic',
        component: () => import('../views/petshop/TakePic.vue'),
        meta: {
          keepAlive: true,
          crumb: ['宠物店管理', '预约', '拍照预约']
        },
      },
      {
        path: 'fosterage',
        name: 'fosterage',
        component: () => import('../views/petshop/Fosterage.vue'),
        meta: {
          keepAlive: true,
          crumb: ['宠物店管理', '预约', '宠物寄养信息']
        },
      },
    ]
  },
]
const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    next()
  } else {
    if (store.state.token) {
      next()
    } else {
      router.push('login')
    }
  }
  next()
})
export function addroute1() {
  console.log(router)
  const currentRouters = router.options.routes
  currentRouters[3].children.push(...level1)

  router.addRoutes(currentRouters)
}
export function addroute2() {
  console.log(router)
  const currentRouters = router.options.routes
  currentRouters[3].children.push(...level2)

  router.addRoutes(currentRouters)
}
export default router;
